const express = require('express');
const app = express();

app.all("/*", function (req, res, next) {
    // 跨域处理
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next(); // 执行下一个路由
})

const port = process.env.PORT || 5000;  //定义端口号
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: false
}))
//不写的话无法获取到 post 请求

app.get('/', (req, res) => {
    //如果访问根路径的话
    res.send({ msg: "server is works" })
});
const Users = require('./router/Users')
app.use('/', Users)
app.listen(port, () => {
    console.log("server in running on port:" + port);
})